import {Component, OnInit} from '@angular/core';
import {AfterViewInit, ViewChild} from '@angular/core';
import { Router, ActivatedRoute, Params } from '@angular/router';

import {ArticleService} from "../service/article.service";
import {ArticleEditorComponent} from "./articleEditor.component";
import {Article} from "../entity/article";

@Component({
    moduleId: module.id,
    selector: 'my-articleDetail',
    templateUrl: 'articleDetail.component.html',
    styleUrls: ['articleDetail.component.css'],
    providers: [ArticleService]
})

export class ArticleDetailComponent implements OnInit,AfterViewInit {

    @ViewChild(ArticleEditorComponent)
    private articleEditorComponent: ArticleEditorComponent;

    article: Article;
    errorMessage: string;

    ngAfterViewInit() {
        let id = this.route.snapshot.params['id'];
        this.articleService.getArticle(id).then(
            article =>{this.article = article;this.articleEditorComponent.editor.$txt.html(article.content);},
            error => this.errorMessage = <any>error
        );
        this.articleEditorComponent.editor.config.menus = [
            'fullscreen'
        ];
        this.articleEditorComponent.editor.create();
        this.articleEditorComponent.editor.$txt.removeAttr('contenteditable');//设置文章内容不可编辑
        console.log(this.articleEditorComponent.editor.$editorContainer);
    }

    constructor(private articleService: ArticleService,private route: ActivatedRoute,
                private router: Router) {
    }


    ngOnInit(): void {

    }

}